<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas {
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <canvas width="600" height="400" id="canvas">
        <!-- 检测浏览器是否支持canvas 不支持时显示其中文字 -->
        你的浏览器版本过低，请使用其他浏览器！！
    </canvas>
</body>
<script>
    var context  = document.getElementById("canvas").getContext('2d');
    context.moveTo(20, 20);
    context.lineTo(20, 320);
    context.strokeStyle='red';
    context.lineWidth=2;
    context.stroke();
    //开启新的绘制 使下面的设置不影响到上面
    context.beginPath();
    context.moveTo(40, 20);
    context.lineTo(40, 320);
    context.strokeStyle='blue';
    context.lineWidth=2;
    context.stroke();
</script>

</html>